/*自定义--校区管理-课程管理*/
import { routerRedux } from 'dva/router';
import * as LoginService from '../services/basics';

export default {
  namespace: 'campucourse',
  state: {
    data: [],
  },
  effects: {
  	 //单独课程  admin 查询
    *fetch_course({ payload }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/system/getAloneCourse',payload); 
    	yield put({type: 'save',payload: response.data.obj});
    },
    //单独课程 admin 查询单个
    *fetchId_course({ payload ,callback}, { call, put }) {
      const response = yield call(LoginService.get,'/api/web/system/getAloneCourse',payload);
    	callback(response.data.res,response.data.obj);
    },
    //单独课程 admin 新增
    *add_course({ payload, callback }, { call, put }) {
      	const response = yield call(LoginService.post,'/api/web/system/insertAloneCourse', payload);
      	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_course'});
    },
    //单独课程 admin 编辑
    *edit_course({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.puts,'/api/web/system/updateAloneCourse', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_course'});
    },
    //课程 admin 禁用启用
    *disabled_course({ payload, callback }, { call, put }) {
      const response = yield call(LoginService.puts,'/api/web/system/updateAloneCourseState', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_course'});
    },
     //查询 单独课程 select 
	*fetch_courseselect({ payload,callback }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/system/getAloneCourse',payload); 
      	callback(response.data.res,response.data.obj);
    },
    //查询学校 select
    *fetch_ListByschoolselect({ payload,callback }, { call, put }) {  
      	const response = yield call(LoginService.post,'/api/web/school/getSchoolListByOrg'); 
    	callback(response.data.res,response.data.obj);
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
